package com.shop.dao.impl;

import com.shop.dao.AddressDao;
import com.shop.entity.Address;
import com.shop.entity.ShowPageT;
import com.shop.tools.JdbcTool;

import java.sql.SQLException;
import java.util.List;

/**
 * com.shop.dao.impl文档说明
 *
 * @author Angluzha
 * @version 2022/9/22
 */
public class AddressDaoImpl implements AddressDao {
    @Override
    public Address selectOne(Address address) throws SQLException {
        String sql = "select * from t_address where id=?";
        return JdbcTool.selectOne(Address.class,sql,address.getId());
    }

    @Override
    public boolean update(Address a) {
        String sql = "update t_address set name=?,phone=?,address=?,statu=? where id=?";
        return JdbcTool.write(sql,a.getName(),a.getPhone(),a.getAddress(),a.getStatu(),a.getId())>0;
    }

    @Override
    public boolean insert(Address a) {
        String sql = "insert into t_address(uid,name,phone,address,statu) values(?,?,?,?,?)";
        return JdbcTool.write(sql,a.getUid(),a.getName(),a.getPhone(),a.getAddress(),a.getStatu())>0;
    }

    @Override
    public boolean deleteById(Integer id) {
        String sql = "delete from t_address where id=?";
        return JdbcTool.write(sql,id)>0;
    }

    @Override
    public List<Address> selectAll() throws SQLException {
        String sql = "select * from t_address";
        return JdbcTool.selectList(Address.class,sql);
    }

    public List<Address> selectListByUid(Integer uid) throws SQLException {
        String sql = "select * from t_address where uid = ?";
        return JdbcTool.selectList(Address.class,sql,uid);
    }

    @Override
    public ShowPageT<Address> selectPage(ShowPageT<Address> page) throws SQLException {
        return null;
    }

    @Override
    public int delCheck(List<Integer> list) {
        return 0;
    }
}
